<?php

function get_user_list($con)
{
	$query = "SELECT * FROM user ORDER BY id DESC";
	return select($con, $query);
}

function get_user($con, $id)
{
	$query = "SELECT * FROM user WHERE id = '$id' LIMIT 1";
	$records = select($con, $query);
	if(count($records) == 1) {
		return $records[0];
	}
	else {
		return NULL;
	}
}

function insert_user($con, $user)
{
	$username	= $user["username"];
	$password	= $user["password"];
	$email		= $user["email"];
	$is_admin	= $user["is_admin"];
	
	$query = "INSERT INTO user(username, password, email, is_admin)" .
		" VALUES ('$username', '$password', '$email', '$is_admin')";
	
	return insert($con, $query);
}

function update_user($con, $user)
{
	$id			= $user["id"];
	$username	= $user["username"];
	$password	= $user["password"];
	$email		= $user["email"];
	$is_admin	= $user["is_admin"];
	
	$query = "UPDATE user SET username = '$username', password = '$password', " .
		"email = '$email', is_admin = '$is_admin' " .
		"WHERE id = '$id'";
	
	return update($con, $query);
}

function check_user($con,$user){
	$username=$user['username'];
	$password=$user['password'];
	$query="select * from user where username='$username' and password='$password'";
	echo $query;
	return select($con,$query); 
}
